<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>会员消息列表</title>
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>会员消息标题：<input type="text" id="message_title" class="form-control input-sm w300"  name="message_title" value="" /></span>
                                    <input type="button" value="查询" class="btn btn-primary" onclick="message.search();" />&nbsp;&nbsp;
                                    <input type="button" value="重置" class="btn btn-warning" onclick="message.reset();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<div id="pop" style="display: none">

    <div class="panel">

        <div class="panel-body">

            <form id="item_form" onsubmit="return false;" class="form-horizontal">

                <input type="hidden" id="message_id" name="message_id" value="0" />

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="save_message_title">
                        <span class="red">*</span>
                        会员消息标题：
                    </label>
                    <div class="col-sm-9">
                        <input id="save_message_title" class="form-control w300" type="text" placeholder="请输入会员消息标题" name="save_message_title" >&nbsp;&nbsp;

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label" for="message_content" style="width:23%;">
                        <span class="red">*</span>
                        会员消息内容：
                    </label>
                    <div class="col-sm-9">
                        <textarea name="message_content" id="message_content" style="width:100%;height:400px;"></textarea>
                    </div>
                </div>

            </form>

        </div>

    </div>

</div>


<!--导入 开始-->
<div id="import" style="display: none;">
    <form id="upload_form" name="upload_form" method="post" enctype="multipart/form-data" action="/quanliadmin/app/customer/message.pscript?operFlg=2&message_id=" target="hide_frame">
        <span style="display: inline-block;">
            <input size="30" type="file" id="search_file" name="search_file" >
        </span>
        <input type="button" name="into_sub" id="into_sub" class="btn btn-primary" value="导入">
        <span id="importMsg" style="line-height: 30px;"></span>
        <iframe id="hide_frame" name="hide_frame" style="display: none;"></iframe>
    </form>
</div>
<!--导入 结束-->


<script type="text/javascript">

$(document).on('click','#into_sub',function(){
    var filename = $('#search_file').val();
    if(filename == ''){
        message.importMsg('请选择上传文件',0);
        return false;
    }

    var basename = filename.split(".");
    if(basename[basename.length-1].toLowerCase() != 'xlsx'){
        message.importMsg('文件类型错误，请选择xlsx文件',0);
        return false;
    }

    $("#importMsg").css("color","black");
    $("#importMsg").text("正在导入，请稍后...");

    $("#upload_form").submit();

});

$("#flex").flexigrid({
    url:"/invokingAjax-backend/customer/message.ajax?operFlg=1",
    dataType: "json",
    colModel : [
        <!--{if $edit_permission}-->
        {display: "操作", width : 150, align: "center"},
        <!--{/if}-->
        {display: "创建时间", align: "center", width : 150, name : "message_id", sortable : true},
        {display: "会员消息标题", align: "left", width : 500}
    ],
    <!--{if $edit_permission}-->
    buttons : [
        {name: "添加", bclass: "add", onpress : "message.edit.open"},
        {separator: true},
        {name: "删除", bclass: "delete", onpress : "message.del"},
        {separator: true},
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
    ],
    <!--{/if}-->
    sortname: "message_id",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    autoload: true,
    onSubmit: function() {
        var dt = $("#search_form").serializeArray();
        $("#flex1").flexOptions({params: dt});
        return true;
    }
});

var message = {

    message_id:'',

    //搜索会员
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },
    //重置
    reset: function() {
        $('#message_title').val('');

        this.search();
    },

    //添加或修改会员消息
    edit: {

        open: function( message_id ) {

            if (!message_id) {
                message_id = 0;
            }

            E.popup.open({
                id: 'pop',
                title: message_id == 0 ? '添加会员消息' : '修改会员消息',
                css: 'width: 800px;',
                btnName: '保存',
                btnCall: 'message.edit.save();'
            });

            if (message_id > 0) {

                E.ajax_get({
                    url: '/invokingAjax-backend/customer/message.ajax?operFlg=2',
                    data: {
                        message_id: message_id
                    },
                    call: function( o ) {

                        if (o.code == 200) {
                            $('#message_id').val(o.data.message_id);
                            $('#save_message_title').val(o.data.message_title);
                            $('#message_content').html(o.data.message_content);
                            window.editor = KindEditor.create("#message_content");
                        }
                    }
                });

            } else {

                window.editor = KindEditor.create("#message_content");

            }

        },


        save: function() {

            editor.sync();

            var dt = E.getFormValues('item_form');

            var error_msg = '';

            if (E.isEmpty(dt.save_message_title))
                error_msg += '会员消息不能为空<br/>';

            if (E.isEmpty(dt.message_content))
                error_msg += '会员消息内容不能为空<br/>';

            if (error_msg != '') {

                E.alert(error_msg);

            } else {

                E.confirm('您确认保存修改会员消息吗？', function() {

                    E.loadding.open('正在保存，请稍候...');

                    E.ajax_post({
                        url: '/invokingAjax-backend/customer/message.ajax?operFlg=100&act=edit',
                        data: dt,
                        call: function( o ) {
                            E.loadding.close();
                            if (o.code == 200) {
                                E.popup.close();
                                E.alert(o.message, 2, 'message.load');
                            } else {
                                E.alert(o.message);
                            }
                        }
                    });

                });

            }

        }

    },

    //导入会员消息
    import:function( message_id ){
        $("#upload_form").attr("action","/quanliadmin/app/customer/message.pscript?operFlg=2&message_id="+message_id);
        E.popup.open({
            id: 'import',
            title: '导入会员消息',
            css: 'width: 500px;'
        });
    },

    /**
     * 导入会员消息的信息
     * @param msg  文字信息
     */
    importMsg : function (msg, flg){
        if(flg == 0){
            $("#importMsg").css("color","red");
        }else{
            $("#importMsg").css("color","green");
            //更新 input file
            var input_html = $("#search_file").clone();
            $("#search_file").remove();
            $("#searchForm").prepend(input_html);
            msg = "导入成功";
        }
        $("#importMsg").text(msg);
    },

    del: function() {

        var p_obj = $('#flex').find('tr.trSelected');
        if (p_obj.length == 0) {
            E.alert('请选择要删除的会员消息');
        } else {

            var p_array = new Array();
            $.each(p_obj, function(k, v) {
                var id = $(v).attr('id').replace('row', '');
                p_array.push(id);
            });

            E.confirm('您确认要删除选中的会员消息吗？', function() {

                E.loadding.open('正在删除，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/customer/message.ajax?operFlg=100&act=del',
                    data: {
                        p_array: p_array
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            E.alert('删除成功', 2, 'message.load');
                        } else {
                            E.alert(o.message);
                        }
                    }
                });

            });

        }

    },

    //已发消息查看
    sentMessage: function(message_id){
        self.location = '/quanliadmin/app/customer/message.pscript?operFlg=3&message_id='+message_id;
    },

    load: function() {
        $("#flex").flexReload();
    }

}

</script>

</body>
</html>